package top.bug.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.bug.blog.entity.po.SysOperationLog;
import top.bug.blog.mapper.OperationLogMapper;
import top.bug.blog.service.OperationLogService;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author <a href="https://github.com/jiusi66">九思.</a>
 * @email 10837907@qq.com
 * @from <a href="https://www.52bug.top">递归茶馆-www.52bug.top</a>
 * @description 后台操作日志 实现类
 */
@Service
public class OperationLogServiceImpl extends ServiceImpl<OperationLogMapper, SysOperationLog> implements OperationLogService {
    @Resource
    private OperationLogMapper operationLogMapper;

    @Override
    public void saveAsync(SysOperationLog log) {
        this.save(log);
    }

    @Override
    public int deleteBeforeDate(LocalDateTime threshold) {
        return operationLogMapper.delete(new LambdaQueryWrapper<SysOperationLog>()
                .le(SysOperationLog::getCreateOn, threshold));
    }
}
